package com.ptszyxx.popose.module.main.mine.vm;

import android.app.Application;

import androidx.annotation.NonNull;

import com.ptszyxx.popose.R;
import com.ptszyxx.popose.common.utils.YActivityUtil;
import com.ptszyxx.popose.common.utils.YLoginUtil;
import com.ysg.base.BaseViewModel;
import com.ysg.binding.command.BindingCommand;
import com.ysg.bus.event.SingleLiveEvent;
import com.ysg.http.HttpUtils;
import com.ysg.http.data.CommonRepository;
import com.ysg.utils.YToastUtil;

import java.util.HashMap;
import java.util.Map;

public class MineAccountVM extends BaseViewModel<CommonRepository> {

    public MineAccountVM(@NonNull Application application, CommonRepository model) {
        super(application, model);
    }

    public UIChangeObservable uc = new UIChangeObservable();
    public class UIChangeObservable {
        public SingleLiveEvent onCancelEvent = new SingleLiveEvent<>();
    }

    public BindingCommand onPasswordCommand = new BindingCommand(() ->
            YActivityUtil.getInstance().jumpPassword(this)
    );
    public BindingCommand onCancelCommand = new BindingCommand(() ->
        uc.onCancelEvent.call()
    );
    //=========================================接口：start===========================================

    /**
     * 账户注销
     */
    public void requestWriteOff(){
        Map<String, String> map = new HashMap<>();
        HttpUtils.getInstance()
                .data(model.writeOff(map), this, (v)->{
                    YToastUtil.showShort(R.string.success);
                    YLoginUtil.getInstance().logout(getApplication());
                });
    }

}
